package com.goodmr.passport.webapp.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 错误信息数据包
 *
 * @author <a href="mailto:bingdong13@msn.com">bigo</a>
 */
@Getter
public enum ErrorEnum {

    INTERNAL_SERVER_ERROR(500000, "internal.server.error", "server/system"),
    REQUEST_PARAM_ERROR(500101, "request.param.error", "client/param"),
    UNAUTHORIZED(500103, "unauthorized", "client/auth"),

    ACCOUNT_FORMAT_ERROR(1000101, "account.format.error", "client/account"),
    ACCOUNT_MOBILE_EXIST(100102, "account.mobile.exist", "client/account"),
    ACCOUNT_EMAIL_EXIST(100103, "account.email.exist", "client/account"),
    ACCOUNT_NOT_EXIST(100104, "account.not.exist", "client/account"),
    ACCOUNT_NOT_NORMAL(100105, "account.not.normal", "server/account"),
    ACCOUNT_PASSWORD_ERROR(100106, "account.password.error", "client/account"),

    PASSWORD_FORMAT_ERROR(1000201, "password.format.error", "client,password"),
    ;

    /**
     * 错误码
     */
    private int code;

    /**
     * 错误信息（默认值）
     */
    private String module;

    /**
     * 资源标识（多语言）
     */
    private String resource;

    /**
     * 错误参数，用于填充占位符的数据
     */
    private List<Object> args;

    ErrorEnum(int code, String resource, String module) {
        this.code = code;
        this.resource = resource;
        this.module = module;

        this.args = new ArrayList<>();
        this.args.add(module);
    }

    /**
     * 设置错误参数
     *
     * @param args 错误参数
     */
    public void setArgs(List<Object> args) {
        this.args.addAll(args);
    }
}
